package com.study.twolist;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 求两个List的不同
 *
 * @author yyb8152
 * @since 20220809
 **/
public class TwoList {
    public static void main(String[] args) {
        // 原始初始化的数组
        List<Integer> listOne = Arrays.asList(1, 2, 3, 4);
        // 编辑后变更的数组
        List<Integer> listTwo = Arrays.asList(2, 4, 6, 8);

        // 过滤出需要删除的数
        List<Integer> deleteList = listOne.stream().filter(list -> !listTwo.contains(list)).collect(Collectors.toList());
        System.out.println("需要删除的数" + deleteList);

        // 过滤出新增的数
        List<Integer> addList = listTwo.stream().filter(list -> !listOne.contains(list)).collect(Collectors.toList());
        System.out.println("需要新增的数" + addList);

        // 过滤出需要编辑的数
        List<Integer> upDateList = listOne.stream().filter(list -> listTwo.contains(list)).collect(Collectors.toList());
        System.out.println("需要更新的数" + upDateList);

    }
}
